// 自定义居中弹窗工具类
import 'package:flutter/material.dart';

class CenterSnackBar {
  static void show(BuildContext context, String message, {int seconds = 2}) {
    final overlay = Overlay.of(context);
    final overlayEntry = OverlayEntry(
      builder: (context) => Center(
        child: Material(
          color: Colors.transparent, // 透明背景
          child: Container(
            constraints: BoxConstraints(
                maxWidth: MediaQuery.of(context).size.width * 0.8),
            decoration: BoxDecoration(
              color: Colors.black54,
              borderRadius: BorderRadius.circular(8),
            ),
            padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
            child: Text(
              message,
              textAlign: TextAlign.center,
              style: const TextStyle(color: Colors.white, fontSize: 16),
            ),
          ),
        ),
      ),
    );

    // 插入弹窗
    overlay.insert(overlayEntry);

    // 自动关闭
    Future.delayed(Duration(seconds: seconds)).then((_) {
      overlayEntry.remove();
    });
  }
}
